<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions" 
  xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
  xmlns:camunda="http://camunda.org/schema/1.0/bpmn"
  targetNamespace="Examples">

  <error id="Error_1" errorCode="error1" name="error1"/>
  
  <process id="compensateProcess" isExecutable="true">

    <startEvent id="start" />

    <sequenceFlow sourceRef="start" targetRef="subProcess" />
    
    <subProcess id="subProcess">
    
      <startEvent id="startSubProcess" />

      <sequenceFlow sourceRef="startSubProcess" targetRef="fork" />

      <parallelGateway id="fork" />
  
      <sequenceFlow sourceRef="fork" targetRef="bookHotel" />
      <sequenceFlow sourceRef="fork" targetRef="bookFlight" />
  
      <serviceTask id="bookHotel" camunda:expression="${true}">
        <multiInstanceLoopCharacteristics isSequential="true">
          <loopCardinality>5</loopCardinality>
        </multiInstanceLoopCharacteristics>
      </serviceTask>
  
      <boundaryEvent id="compensateBookHotelEvt" name="Boundary event" attachedToRef="bookHotel">
        <compensateEventDefinition />
      </boundaryEvent>
  
      <serviceTask id="undoBookHotel" isForCompensation="true"
        camunda:class="org.camunda.bpm.engine.test.bpmn.event.compensate.helper.UndoService">
        <extensionElements>
          <camunda:field name="counterName" stringValue="undoBookHotel" />
        </extensionElements>
      </serviceTask>  
  
      <serviceTask id="bookFlight" camunda:expression="${true}">
        <multiInstanceLoopCharacteristics isSequential="true">
          <loopCardinality>5</loopCardinality>
        </multiInstanceLoopCharacteristics>
      </serviceTask>
  
      <boundaryEvent id="compensateBookFlightEvt" name="Boundary event" attachedToRef="bookFlight">
        <compensateEventDefinition  />
      </boundaryEvent>
  
      <serviceTask id="undoBookFlight" isForCompensation="true"
        camunda:class="org.camunda.bpm.engine.test.bpmn.event.compensate.helper.UndoService">
        <extensionElements>
          <camunda:field name="counterName" stringValue="undoBookFlight" />
        </extensionElements>
      </serviceTask>
  
      <parallelGateway id="join" />
  
      <sequenceFlow sourceRef="bookHotel" targetRef="join" />
      <sequenceFlow sourceRef="bookFlight" targetRef="join" />
      <sequenceFlow sourceRef="join" targetRef="endSubProcess" />
  
      <endEvent id="endSubProcess" >
        <errorEventDefinition errorRef="Error_1"/>
      </endEvent>
  
      <subProcess id="eventSubProcess" triggeredByEvent="true">
      
        <startEvent id="startEventSubProcess" name="Reisebuchung">
          <errorEventDefinition errorRef="Error_1"/>
        </startEvent>
        
        <sequenceFlow sourceRef="startEventSubProcess" targetRef="throwCompensate" />
        
        <intermediateThrowEvent id="throwCompensate">
          <compensateEventDefinition activityRef="bookHotel" />
        </intermediateThrowEvent>
        
        <sequenceFlow sourceRef="throwCompensate" targetRef="endEventSubProcess" />
        
        <endEvent id="endEventSubProcess" />
  
      </subProcess>
    
      <association associationDirection="One" sourceRef="compensateBookHotelEvt" targetRef="undoBookHotel" />
      <association associationDirection="One" sourceRef="compensateBookFlightEvt" targetRef="undoBookFlight" />
      
    </subProcess>
    
    <sequenceFlow sourceRef="subProcess" targetRef="end"/>
    
    <endEvent id="end"/>
    
  </process>

</definitions>
